package edu.huangke.controller;
import edu.huangke.pojo.User;
import org.springframework.http.HttpCookie;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * 数据绑定
 */
@Controller
public class UserController {

    @RequestMapping("/registerUser")
    public void registerUser(User user) {
        String username = user.getUserName();
        String password = user.getPassword();
        System.out.println("username="+username+",password="+password);

    }

    /**
     *     HttpServletRequest：通过request对象获取请求信息。
     *     HttpServletResponse：通过response处理响应信息。
     *     HttpSession：通过session对象得到session中存放的对象。
     *     Model/ModelMap：Model是一个接口，ModelMap是一个类，
     *     Model的实现类对象和ModelMap对象都可以设置model数据，
     *     model数据会填充到request域。
     */

    @RequestMapping("/getUserId")
    public void getUserId(HttpServletRequest request,
                            HttpServletResponse response,
                                    HttpSession session,
                                Model model
    ){
        System.out.println(response);
        System.out.println(session);

        // 向模型中存放数据
        model.addAttribute("msg","今天天气真不错");

        String userid= request.getParameter("userid");
        System.out.println("userid="+userid);
    }



    //  自定义类型转换器
    // 浏览器请求 birthday = 2025-01-01
    @RequestMapping("/getBirthday")
    public String getBirthday(Date birthday) {

        System.out.println("birthday="+birthday);
        return "hello";
    }


    @RequestMapping("/findOrderWithUser")
    public String findOrderWithUser(User user) {
        System.out.println(user.getUserName());
        System.out.println(user.getOrder().getOrderID());

        return "hello";
    }

}
